package com.paic.hmily.dialog.app;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.paic.hmily.dialog.library.CustomCircleLineProgressBar;

import java.util.Timer;
import java.util.TimerTask;

/**
 * 主界面。
 *
 * @author hehui
 *         ~
 * @date 2016/11/6 12:23
 */
public class MainActivity extends AppCompatActivity {

    private Timer mTimer1;
    private Timer mTimer2;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        startCustomCircleLineProgressBarTask1();

        startCustomCircleLineProgressBarTask2();
    }

    private void startCustomCircleLineProgressBarTask1() {
        final CustomCircleLineProgressBar customCircleLineProgressBar = (CustomCircleLineProgressBar)
                findViewById(R.id.custom_circle_line_progress_bar_1);

        mTimer1 = new Timer();
        mTimer1.schedule(new TimerTask() {

            @Override
            public void run() {
                customCircleLineProgressBar.setProgress(customCircleLineProgressBar.getProgress() + 0.02f);
            }
        }, 0, 1000);
    }

    private void startCustomCircleLineProgressBarTask2() {
        final CustomCircleLineProgressBar customCircleLineProgressBar = (CustomCircleLineProgressBar)
                findViewById(R.id.custom_circle_line_progress_bar_2);

        mTimer2 = new Timer();
        mTimer2.schedule(new TimerTask() {

            @Override
            public void run() {
                customCircleLineProgressBar.setProgress(customCircleLineProgressBar.getProgress() + 0.02f);
            }
        }, 0, 1000);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mTimer1 != null) {
            mTimer1.cancel();
            mTimer1 = null;
        }
        if (mTimer2 != null) {
            mTimer2.cancel();
            mTimer2 = null;
        }

        // 结束进程
        android.os.Process.killProcess(android.os.Process.myPid());
    }
}